Repository navigation
Audit zend_ini_string() and related functions - #21146
Conversation
58f9395 to
5095e2f
Compare
13411e8 to
cb2e357
Compare
arnaud-lb
left a comment
There was a problem hiding this comment.
Looks good to me.
One caveat with ZEND_STRL() is that it would break if the outer function call was turned into a macro, as it is seen as a single argument during expansion.
An alternative to removing INI_STR(), that would also eliminate the need for ZEND_STRL(), would be to introduce _literal variants of zend_ini_str(ing)(_ex), like we have in the string API, and then remove or deprecate INI_STR(). But then we might want to also add _literal variants of the other zend_ini_ functions to replace all INI_ macros. No strong opinion on this.
I quite like the idea of using a new literal API variant, will do this and check what the usage of thoses macros are with sourcegraph to see if it is reasonable to remove them outright or not. |
cb2e357 to
76ebba6
Compare
76ebba6 to
fb66db3
Compare
A sourcegraph search shows 0 results other than for the buggy BOOL one in ext/tidy
It is used as a target for snprintf, so must be mutable
…y string rather than NULL in certain cases
dfa590f to
a59fa1c
Compare
TimWolla
left a comment
There was a problem hiding this comment.
I'm having some trouble figuring out which of these changes change behavior and which are simple refactoring (the distinction might be important for bisecting if a change turns out to be buggy).
Changes themselves look good now, though.
| spprintf(&libpath, 0, "%s%s", ZSTR_VAL(extension_dir), *path); /* SAFE */ | ||
| } else { | ||
| spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, *path); /* SAFE */ | ||
| spprintf(&libpath, 0, "%s%c%s", ZSTR_VAL(extension_dir), DEFAULT_SLASH, *path); /* SAFE */ |
There was a problem hiding this comment.
I just remembered we have support for zend_string in our printf implementation. Does this work?
| spprintf(&libpath, 0, "%s%c%s", ZSTR_VAL(extension_dir), DEFAULT_SLASH, *path); /* SAFE */ | |
| zend_spprintf_unchecked(&libpath, 0, "%S%c%s", extension_dir, DEFAULT_SLASH, *path); /* SAFE */ |
Same for the other case.
There was a problem hiding this comment.
I was planning on doing a follow-up refactoring to use the string concat API.
| php_openssl_netstream_data_t *sslsock = (php_openssl_netstream_data_t*)stream->abstract; | ||
|
|
||
| GET_VER_OPT_STRING("cafile", cafile); | ||
| GET_VER_OPT_STRING("capath", capath); | ||
|
|
||
| if (cafile == NULL) { | ||
| cafile = zend_ini_string("openssl.cafile", sizeof("openssl.cafile")-1, 0); | ||
| cafile = strlen(cafile) ? cafile : NULL; | ||
| const zend_string *cafile_str = zend_ini_str_literal("openssl.cafile"); |
There was a problem hiding this comment.
You could have just preserved the original strlen() logic here, but given the cafile_str is locally scoped, this is probably fine.
Replace INI_INT/INI_STR with zend_ini_long_literal/zend_ini_str_literal per the INI API audit that removed the old macros (php/php-src#21146).
Conflicts with #21143I audited the usage of
zend_ini_string()and co as I believe these functions should return aconst char*because they point to a pointer owner by azend_string *.The two other things I am wondering is
INI_STR()macro as it doesn't follow the usual convention of "string" being achar*and "str" meaning azend_string*.INI_ORIG_*macros as they seem mostly pointless?